<template>
  <view>
    <cu-custom bgColor="bg-gradual-blue" :isBack="true">
      <block slot="content" v-if="type=='ruku'">入库单</block>
      <block slot="content" v-else-if="type=='chuku'">出库单</block>
    </cu-custom>

    <scroll-view class="bg-white nav fixed" style="top:40px" scroll-x scroll-with-animation>
      <view class="flex text-center ">
        <view class="cu-item flex-sub" :class="item.type==type?'text-orange cur':''" v-for="(item,index) in cateList"
          :key="index" @tap="tabSelect(item.type)" :data-categoryName="item.cate_name">
          {{item.cate_name}}
        </view>
      </view>
    </scroll-view>

    <view style="height: 45px;"></view>

    <view class="cu-list menu-avatar no-padding" v-if="erpOrderResult.records && erpOrderResult.records.length>0">
      <view class="cu-item" v-for="(item, i) in erpOrderResult.records" :key="i" @tap="doViewOrder(item)">
        <view class="cu-avatar round lg" v-if="type=='ruku'">入</view>
        <view class="cu-avatar round lg" v-else-if="type=='chuku'">出</view>
        <view class="content">
          <view class="text-grey text-xsl">{{item.orderSn}}</view>
          <view class="text-gray text-sm">
            {{item.createTime}}
          </view>
        </view>

        <view class="action">
          <view class="text-red text-bold">{{item.goodsCnt}}</view>
          <view class="text-gray text-sm">数量</view>
        </view>

        <view class="action">
          <view class="text-red text-bold">{{item.amount}}</view>
          <view class="text-gray text-sm">金额</view>
        </view>


      </view>

      <view style="height: 80px;"></view>
    </view>


  </view>
</template>

<script>
  export default {
    data() {
      return {
        type: '',
        cateList: [{
          type: 'ruku',
          cate_name: '入库单'
        }, {
          type: 'chuku',
          cate_name: '出库单'
        }],
        erpOrderResult: {
          records: []
        }
      }
    },
    onLoad(opt) {
      this.type = opt.type ? opt.type : 'ruku'
      console.log("------")
      console.log(opt)

      this.loadData()
    },
    methods: {
      tabSelect(type) {
        this.type = type;
        this.loadData()
      },
      loadData() {
        let that = this
        this.loadding = true

        let url = '/erp/erpOrder/list';
        this.$http.get(url, {
          params: {
            pageSize: 100,
            orderType: this.type == 'ruku' ? '入库' : '出库'
          }
        }).then(res => {
          this.loadding = false

          let result = res.data.result;
          let tmp_result = {
            records: []
          }
          result.records.forEach(_row => {
            // _row.showzi = ""
            // if (_row.goodsName.indexOf('卫') !== -1) {
            //   _row.shouzi = '卫'
            // } else if (_row.goodsName.indexOf('响') !== -1) {
            //   _row.shouzi = '响'
            // } else if (_row.goodsName.indexOf('韵') !== -1) {
            //   _row.shouzi = '韵'
            // } else if (_row.goodsName.indexOf('响') !== -1) {
            //   _row.shouzi = '响'
            // } else if (_row.goodsName.indexOf('阳') !== -1) {
            //   _row.shouzi = '阳'
            // } else if (_row.goodsName.indexOf('本') !== -1) {
            //   _row.shouzi = '本'
            // } else {
            //   _row.shouzi = _row.goodsName.length > 0 ? _row.goodsName.substr(0, 1) : ""
            // }

            // tmp_result.records.forEach(__row => {
            // })

            // console.log(_row.shouzi)
          })

          if (res.data.success) {
            this.erpOrderResult = res.data.result
          }

        }).catch(e => {
          this.loadding = false
          console.log(e)
        })
      },
      doViewOrder(item) {
        let url = "";
        if (item.orderType == '入库') {
          url = "/pages/erp/ruku?id=" + item.id
        } else {
          url = "/pages/erp/chuku?id=" + item.id
        }
        uni.navigateTo({
          url: url
        })
      }
    }
  }
</script>

<style>

</style>
